package com.lzy.mall.ware.controller;


import cn.hutool.core.collection.CollUtil;
import com.lzy.mall.common.utils.PageUtils;
import com.lzy.mall.common.utils.ResultUtils;
import com.lzy.mall.ware.entity.WmsWareInfo;
import com.lzy.mall.ware.service.WmsWareInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * 仓库信息(WmsWareInfo)表控制层
 *
 * @author lzy
 * @since 2021-08-24 19:01:48
 */
@RestController
@RequestMapping("wareinfo")
@RequiredArgsConstructor(onConstructor_ = {@Autowired})
@Slf4j
public class WmsWareInfoController {
    private final WmsWareInfoService wareInfoService;

    @GetMapping("/fare")
    public ResultUtils getFare(@RequestParam("addrId") Long addrId){
        return ResultUtils.ok().setData(wareInfoService.getFare(addrId));
    }

    @GetMapping("/list")
    public ResultUtils list(@RequestParam Map<String,Object> params){
        PageUtils page = wareInfoService.queryPage(params);
        return ResultUtils.ok().put("page",page);
    }

    @RequestMapping("/info/{id}")
    //@RequiresPermissions("ware:wareinfo:info")
    public ResultUtils info(@PathVariable("id") Long id){
        WmsWareInfo wareInfo = wareInfoService.getById(id);

        return ResultUtils.ok().put("wareInfo", wareInfo);
    }

    @PostMapping("/save")
    public ResultUtils save(@RequestBody WmsWareInfo wareInfo){
        wareInfoService.save(wareInfo);
        return ResultUtils.ok();
    }

    @PostMapping("/update")
    public ResultUtils update(@RequestBody WmsWareInfo wareInfo){
        wareInfoService.update(wareInfo);
        return ResultUtils.ok();
    }

    @PostMapping("/delete")
    public ResultUtils delete(@RequestBody Long[] ids){
        wareInfoService.removeBatch(CollUtil.toList(ids));
        return ResultUtils.ok();
    }
}
